﻿#include "Calculator.h"
#include <QApplication>
#include <QDebug>
#include <QPushButton>
#include <QSettings>
#include <QString>
#include <QTextCodec>
#include <qtranslator.h>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    //设置中文编码
#if (QT_VERSION <= QT_VERSION_CHECK(5, 0, 0))
#if _MSC_VER
    QTextCodec *codec = QTextCodec::codecForName("gbk");
#else
    QTextCodec *codec = QTextCodec::codecForName("utf-8");
#endif
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForTr(codec);
#else
    QTextCodec *codec = QTextCodec::codecForName("utf-8");
    QTextCodec::setCodecForLocale(codec);
#endif

    app.setOrganizationName("Trolltech");
    app.setApplicationName("Calculator");

    QTranslator qt_translator, app_translator;
    qt_translator.load("qt_zh_CN");
    app_translator.load("Chinese");

    QSettings settings;
    bool isEnglish = settings.value("language", 0).toBool(); //设置应用程序的语言
    if (isEnglish == false)
    {
        app.installTranslator(&qt_translator);
        app.installTranslator(&app_translator);
    }

    Calculator *calculator = new Calculator;
    calculator->show();

    return app.exec();
}
